package com.cmc.cloud.cmclink.doc.api.document;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.api.document.rep.*;
import com.cmc.cloud.cmclink.doc.api.document.req.BlnoCntrRecordationRespVO;
import com.cmc.cloud.cmclink.doc.entity.BlnoCntrRecordationDO;
import com.cmc.cloud.cmclink.doc.service.si.BlnoCntrRecordationService;
import com.cmc.cloud.cmclink.doc.vo.blnocntrrecordationvo.BlnoCntrRecordationCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnocntrrecordationvo.BlnoCntrRecordationOperationVO;
import com.cmc.cloud.cmclink.doc.vo.blnocntrrecordationvo.BlnoCntrRecordationPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnocntrrecordationvo.BlnoCntrRecordationQuery;
import com.cmc.cloud.cmclink.doc.vo.blnocntrrecordationvo.BlnoCntrRecordationUpdateReqVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wdq
 * @date 2025/7/7
 */
@RestController
@Validated
public class BlnoCntrRecordApiImpl implements BlnoCntrRecordApi {

    @Resource
    private BlnoCntrRecordationService blnoCntrRecordationService;

    @Override
    public CommonResult<Void> createBlnoCntrRecordation(BlnoCntrRecordationOperationDto createReqVO) {
        BlnoCntrRecordationOperationVO blnoCntrRecordationOperationVO = BeanUtil.copyProperties(createReqVO, BlnoCntrRecordationOperationVO.class);
        blnoCntrRecordationOperationVO.setCreateReqVO(BeanUtil.copyToList(createReqVO.getCreateReqVO(),BlnoCntrRecordationCreateReqVO.class));
        blnoCntrRecordationService.createBlnoCntrRecordation(blnoCntrRecordationOperationVO);
        return CommonResult.success();
    }

    @Override
    public CommonResult<Void> updateBlnoCntrRecordation(BlnoCntrRecordationUpdateDto updateReqVO) {
        blnoCntrRecordationService.updateBlnoCntrRecordation(BeanUtil.copyProperties(updateReqVO, BlnoCntrRecordationUpdateReqVO.class));
        return CommonResult.success();
    }

    @Override
    public CommonResult<Void> deleteBlnoCntrRecordation(Long id) {
        blnoCntrRecordationService.deleteBlnoCntrRecordation(id);
        return CommonResult.success();
    }

    @Override
    public CommonResult<BlnoCntrRecordationRespVO> getBlnoCntrRecordation(Long id) {
        blnoCntrRecordationService.getBlnoCntrRecordation(id);
        return CommonResult.success();
    }

    @Override
    public CommonResult<List<BlnoCntrRecordationRespVO>> getCntrRecordationList(BlnoCntrRecordationQueryDto queryCntrRecord) {
        List<BlnoCntrRecordationDO> cntrRecordationList = blnoCntrRecordationService.getCntrRecordationList(BeanUtil.toBean(queryCntrRecord, BlnoCntrRecordationQuery.class));
        return CommonResult.success(BeanUtil.copyToList(cntrRecordationList, BlnoCntrRecordationRespVO.class));
    }

    @Override
    public CommonResult<PageResult<BlnoCntrRecordationRespVO>> getBlnoCntrRecordationPage(BlnoCntrRecordationPageDto pageVO) {
        PageResult<BlnoCntrRecordationDO> pageResult = blnoCntrRecordationService.getBlnoCntrRecordationPage(BeanUtil.toBean(pageVO, BlnoCntrRecordationPageReqVO.class));
        List<BlnoCntrRecordationRespVO> results = BeanUtil.copyToList(pageResult.getList(), BlnoCntrRecordationRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
